package com.nageoffer.jobtrain.admin.service.filter;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.nageoffer.jobtrain.admin.dto.req.OjQuestionAddReqDTO;
import com.nageoffer.jobtrain.admin.service.chain.OjQuestionAbstractChainHandler;
import com.nageoffer.jobtrain.common.web.exception.ClientException;
import org.springframework.stereotype.Component;

import static com.nageoffer.jobtrain.admin.common.enums.ChainBizMarkEnum.OJ_QUESTION_CREATE_MARK;

/**
 * author：唐晨
 * 创建Oj题目非空检查责任链实现
 */
@Component
public class OjQuestionCreateParamNotNullChainFilter implements OjQuestionAbstractChainHandler<OjQuestionAddReqDTO> {
    @Override
    public void handler(OjQuestionAddReqDTO requestParam) {
        if (StrUtil.isEmpty(requestParam.getTitle())) {
            throw new ClientException("Oj题目标题不能为空");
        }

        if (ObjectUtil.isEmpty(requestParam.getDifficulty())) {
            throw new ClientException("Oj题目难度不能为空");
        }

        if (ObjectUtil.isEmpty(requestParam.getTimeLimit())) {
            throw new ClientException("Oj题目时间限制不能为空");
        }

        if (ObjectUtil.isEmpty(requestParam.getSpaceLimit())) {
            throw new ClientException("Oj题目空间限制不能为空");
        }

        if (StrUtil.isEmpty(requestParam.getContent())) {
            throw new ClientException("Oj题目内容限制不能为空");
        }

        if (StrUtil.isEmpty(requestParam.getQuestionCase())) {
            throw new ClientException("Oj题目测试用例限制不能为空");
        }

        if (StrUtil.isEmpty(requestParam.getDefaultCode())) {
            throw new ClientException("Oj题目默认代码块限制不能为空");
        }

        if (StrUtil.isEmpty(requestParam.getMainFunction())) {
            throw new ClientException("Oj题目main函数限制不能为空");
        }
    }

    @Override
    public String mark() {
        return OJ_QUESTION_CREATE_MARK.name();
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
